﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.myplandmaterialinfo
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int mpmid = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(mpmid);
                }
            }
        }

        private void ShowInfo(int mpmid)
        {
            lcs.BLL.myplandmaterialinfo bll = new lcs.BLL.myplandmaterialinfo();
            lcs.Model.myplandmaterialinfo model = bll.GetModel(mpmid);
            
            this.txtmname.Text = model.mname;
            this.txtmnum.Text = model.mnum.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {
            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                int mpmid = (Convert.ToInt32(Request.Params["id"]));

                string strErr = "";

                if (this.txtmname.Text.Trim().Length == 0)
                {
                    strErr += "mname不能为空！\\n";
                }
                if (!PageValidate.IsDecimal(txtmnum.Text))
                {
                    strErr += "mnum格式错误！\\n";
                }

                if (strErr != "")
                {
                    MessageBox.Show(this, strErr);
                    return;
                }
                string mname = this.txtmname.Text;
                decimal mnum = decimal.Parse(this.txtmnum.Text);


                lcs.Model.myplandmaterialinfo model = new lcs.Model.myplandmaterialinfo();
                model.mpmid = mpmid;               
                model.mname = mname;
                model.mnum = mnum;

                lcs.BLL.myplandmaterialinfo bll = new lcs.BLL.myplandmaterialinfo();
                bll.Update(model);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "../myplandinfo/list.aspx");
            }

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("../myplandinfo/list.aspx");
        }
    }
}
